***********************************************
* Title: rwanda_headteacher_baseline_jde.do
*
* Author: Todd Pugatch
* Last update: June 10 2024
* Description: data cleaning for Blimpo and Pugatch, "Entrepreneurship Education
*	and Teacher Training in Rwanda," Stage 2 Registered report, Journal of 
*	Development Economics
*
*
* Inputs: HeadTeacher_Survey_cleaned_NOPII.dta		
*
* Outputs: headteacher_baseline_clean_jde.dta
*
* Purpose: cleans head teacher baseline survey
************************************************


* Set environment
local start=`"$S_TIME"'
clear
clear matrix
clear mata
graph drop _all
program drop _all
cap log close
set more off

* Set directories 
*global main "[SET MAIN DIRECTORY HERE]"
	global rawdata "$main/01_data/01_raw"
	global cleandata "$main/01_data/02_clean"
	global dofiles "$main/02_dofiles"
	global results "$main/03_results"
	global out "$main/04_output"

* define exchange rate to convert all variables in FRW into USD
local xrate = 63.5759 

* exchange rate on 1 Mar 2016: http://www.exchangerates.org.uk/USD-RWF-exchange-rate-history-full.html


*********************************************************************
* 					LOAD AND PREPARE DATA
*
* 	variable naming and label conventions: 
*	--names:	use [bl/el] suffix for baseline/endline
*				omit if variable is an identifier that could be used to match
*				across datasets, like treatment status or school code
*	--labels: 	use B/E for baseline/endline 
*				use [H/T/S]Q for head teacher/teacher/student questionnaire
*	--example: enrollment, as reported by head teacher at baseline in item #123
*		name: enroll_bl
*	    label: "BHQ123: enrollment"
*
*********************************************************************
		
use "$rawdata/headteacher/HeadTeacher_Survey_cleaned_NOPII.dta", clear

/*correct coding errors, according to "Manual Checking Report.docx" (Jean Bosco email 24 Nov 2016)*/


/*update discrepancies between treatment status between sampling spreadsheet and dataset*/
replace group_110=2 if school_code_107=="0301112" 	
replace group_110=1 if school_code_107=="0403110" 
replace group_110=1 if school_code_107=="0403037" 	
replace group_110=1 if school_code_107=="0403050" 	
replace group_110=1 if school_code_107=="0305012"	
replace group_110=1 if school_code_107=="0504114"	
replace group_110=2 if school_code_107=="0304031"	
replace group_110=1 if school_code_107=="0304103"	
replace group_110=1 if school_code_107=="0305034"	
replace group_110=2 if school_code_107=="0403111"	

qui destring school_code_107, gen(school_code)  
qui gen schoolname_bl = school
lab var schoolname_bl "school name, as reported in baseline (school)"
lab val schoolname_bl schoollab


************************************************************************
*											   						   *
* 			   SECTION 1: Identifying information	   				   *
* 											   						   *
************************************************************************

/*survey identifying information: need to mark as baseline*/
local X "interview_starttime enumerator_id enumerator_name supervisor_id supervisor_name dataentryclerk_id dataentryclerk_id_other enum_id dataentryclerk_name visit_date_114"

foreach x of local X {
    qui gen `x'_bl = `x'
    lab var `x'_bl "`x', baseline"
}


/*create district & province IDs to match Census/map codes*/
qui gen district_id=.
qui replace district_id=57 if district==1 
qui replace district_id=53 if district==2 
qui replace district_id=54 if district==3 
qui replace district_id=56 if district==4 
qui replace district_id=42 if district==5 
qui replace district_id=45 if district==6 
qui replace district_id=43 if district==7 
qui replace district_id=41 if district==8 
qui replace district_id=31 if district==9 
qui replace district_id=35 if district==10 
qui replace district_id=34 if district==11 
lab var district_id "District ID, Census code"


qui gen province_id=.
qui replace province_id=5 if province==1 /*Eastern*/
qui replace province_id=4 if province==2 /*Northern*/
qui replace province_id=3 if province==3 /*Western*/
lab var province_id "Province ID, Census code"

/*school types*/
qui gen rural=(distrloc_106==1)
qui gen public=(publ_priv_108==1) /*note that there are lots of part public-part private schools*/
qui gen boarding=(board_day_109==1|board_day_109==3)
qui gen treatment=(group_110==1)	
qui replace treatment=. if group_110==.
gen schl_est = substr(sch_year_115, -4, 4)
destring(schl_est), replace
qui gen schl_age_bl=2016-schl_est
qui gen schl_good_condition_bl=(buildcond_117==1)
sort district public
qui egen strata=group(district public)
lab def treatment 0 "control" 1 "treatment"
lab val treatment treatment
lab var rural "BHQ105: school located in rural district"
lab var public "BHQ108: public school"
lab var boarding "BHQ109: boarding school (including boarding/day combo)"
lab var schl_est "BHQ115: year school established"
lab var schl_age_bl "BHQ115: age of school (years)"
lab var schl_good_condition_bl "BHQ117: school buildings in good condition"
notes schl_age_bl: "source: BHQ115"
notes rural: "survey item is BHQ105, but variable name is distrloc_106"
/* see also: buildings_116 = # of school buildings*/

/*alternate versions of treatment (see "Manual Checking Report.docx" for more details)*/
* alternate version 1: code unassigned replacement schools as missing
qui gen treatment_unassgn=treatment
qui replace treatment_unassgn=. if school_code_107=="0305112"	
qui replace treatment_unassgn=. if school_code_107=="0304102"	
qui replace treatment_unassgn=. if school_code_107=="0403121"	
qui replace treatment_unassgn=. if school_code_107=="0503118"	
lab var treatment_unassgn "treatment status (unassigned replacement schools as missing)"

* alternative version 2: code schools with mismatched status between E! and initial assignment;
/*this mismatch was based on IPA error, not E! choice*/
qui gen treatment_educateassgnt=treatment
qui replace treatment_educateassgnt=1 if school_code_107=="0301112" 	
qui replace treatment_educateassgnt=0 if school_code_107=="0403110" 	
qui replace treatment_educateassgnt=0 if school_code_107=="0403037" 	
/*additional mismatches based on E! error, not IPA assignment choice*/
qui replace treatment_educateassgnt=1 if school_code_107=="0503014" 	
qui replace treatment_educateassgnt=0 if school_code_107=="0503104" 	
lab var treatment_educateassgnt "treatment status (based on Educate! records, not initial assignment)"
foreach x in unassgn educateassgnt {
	lab val treatment_`x' treatment
}

**********************************************************************
*											   				 		 *
* 		SECTION 2: Head Teacher Identification, School	 	 		 *
*		Enrollment, Teacher Personnel, Conditions	 	 	 		 *
* 														     		 *
**********************************************************************

/*head teacher id variables*/
	/*other variables in this section: first_name_200 family_name_200
		questions 207/208 not in dataset*/
qui gen ht_bl=(pos_201==1)
qui gen ht_female_bl=(gender_202==1)
qui gen ht_age_bl=age_203 
qui gen ht_exper_bl=floor(years_ht_exp_204)
qui gen ht_exper_teach_bl=years_teach_exp_205
qui gen ht_bach_bl=(grade_educ_206==3)
qui gen ht_mast_bl=(grade_educ_206==4)
lab var ht_bl "BHQ201: head teacher responded to questionnaire"
lab var ht_female_bl "BHQ202: head teacher (or respondent) is female"
lab var ht_age_bl "BHQ203: head teacher (or respondent) age"
lab var ht_exper_bl "BHQ204: head teacher experience (less than 1yr coded as 0)"
lab var ht_exper_teach_bl "BHQ205: head teacher experience as a teacher"
lab var ht_bach_bl "BHQ206: head teacher has bachelor's (A0)"
lab var ht_mast_bl "BHQ206: head teacher has master's"

/*school enrollment*/
qui gen enroll_p_bl=p_stud_t_209
qui gen enroll_p_m_bl=p_stud_m_209
qui gen enroll_p_f_bl=p_stud_f_209
foreach x in p p_m p_f {
	qui replace enroll_`x'_bl=0 if enroll_`x'_bl==.|enroll_`x'_bl==-77
}
lab var enroll_p_bl "BHQ209: school enrollment, primary"
lab var enroll_p_m_bl "BHQ209: school enrollment, primary, male"
lab var enroll_p_f_bl "BHQ209: school enrollment, primary, female"
forval g=1/6 {
	qui gen enroll_s`g'_bl=s`g'_stud_t_209
	qui replace enroll_s`g'_bl=0 if enroll_s`g'_bl==.|enroll_s`g'_bl==-77
	foreach s in m f {
		qui gen enroll_s`g'_`s'_bl=s`g'_stud_`s'_209
		qui gen enroll_s`g'_`s'_miss_bl=(enroll_s`g'_`s'_bl==.|enroll_s`g'_`s'_bl==-77)
	}
	qui gen enroll_s`g'_fpct_bl=enroll_s`g'_f_bl/enroll_s`g'_bl
	lab var enroll_s`g'_bl "BHQ209: school enrollment, S`g'"
	lab var enroll_s`g'_m_bl "BHQ209: school enrollment, S`g', male"
	lab var enroll_s`g'_f_bl "BHQ209: school enrollment, S`g', female"
	lab var enroll_s`g'_m_miss_bl "BHQ209: missing value for school enrollment, S`g', male"
	lab var enroll_s`g'_f_miss_bl "BHQ209: missing value for school enrollment, S`g', female"
	lab var enroll_s`g'_fpct_bl "BHQ209: school enrollment, S`g', proportion female"
}


qui egen enroll_ls_bl=rowtotal(enroll_s1_bl enroll_s2_bl enroll_s3_bl)
qui egen enroll_us_bl=rowtotal(enroll_s4_bl enroll_s5_bl enroll_s6_bl)
qui egen enroll_s_bl=rowtotal(enroll_ls_bl enroll_us_bl)
qui egen enroll_total_bl=rowtotal(enroll_p_bl enroll_ls_bl enroll_us_bl)
foreach s in m f {
	qui egen enroll_ls_`s'_bl=rowtotal(enroll_s1_`s'_bl enroll_s2_`s'_bl enroll_s3_`s'_bl)
	qui egen enroll_us_`s'_bl=rowtotal(enroll_s4_`s'_bl enroll_s5_`s'_bl enroll_s6_`s'_bl) 
	qui egen enroll_s_`s'_bl=rowtotal(enroll_ls_`s'_bl enroll_us_`s'_bl)
}


foreach x in s ls us {
	qui gen enroll_`x'_fpct_bl=enroll_`x'_f_bl/enroll_`x'_bl
}
qui gen all_female_bl=(enroll_us_m_bl==0 & enroll_us_f_bl>0)
qui gen all_male_bl=(enroll_us_f_bl==0 & enroll_us_m_bl>0)
lab var enroll_ls_bl "BHQ209: school enrollment, lower secondary"
lab var enroll_ls_m_bl "BHQ209: school enrollment, lower secondary, male"
lab var enroll_ls_f_bl "BHQ209: school enrollment, lower secondary, female"
lab var enroll_ls_fpct_bl "BHQ209: school enrollment, lower secondary, proportion female"
lab var enroll_us_bl "BHQ209: school enrollment, upper secondary"
lab var enroll_us_m_bl "BHQ209: school enrollment, upper secondary, male"
lab var enroll_us_f_bl "BHQ209: school enrollment, upper secondary, female"
lab var enroll_us_fpct_bl "BHQ209: school enrollment, upper secondary, proportion female"
lab var enroll_s_bl "BHQ209: school enrollment, secondary"
lab var enroll_s_m_bl "BHQ209: school enrollment, secondary, male"
lab var enroll_s_f_bl "BHQ209: school enrollment, secondary, female"
lab var enroll_s_fpct_bl "BHQ209: school enrollment, secondary, proportion female"
lab var enroll_total_bl "BHQ209: school enrollment, total"
lab var all_female_bl "BHQ209: all female school (based on S4-S6 enrollment)"
lab var all_male_bl "BHQ209: all male school (based on S4-S6 enrollment)"

/*teacher personnel*/
foreach x in m f {
	qui gen teach_p_`x'_bl=p_teach_`x'_210
	qui gen teach_ls_`x'_bl=lower_s_teach_`x'_210
	qui gen teach_us_`x'_bl=upper_s_teach_`x'_210
	foreach l in p ls us {
	}
}

foreach l in p ls us {
	qui egen teach_`l'_bl=rowtotal(teach_`l'_m_bl teach_`l'_f_bl)
	qui gen teach_`l'_miss_bl=(teach_`l'_bl==.)
	qui gen teach_`l'_fpct_bl=teach_`l'_f_bl/teach_`l'_bl
}
qui gen teach_total_bl=teach_p_bl+teach_ls_bl+teach_us_bl
lab var teach_p_bl "BHQ210: teachers, primary"
lab var teach_p_m_bl "BHQ210: male teachers, primary"
lab var teach_p_f_bl "BHQ210: female teachers, primary"
lab var teach_p_fpct_bl "BHQ210: proportion female teachers, primary"
lab var teach_ls_bl "BHQ210: teachers, lower secondary"
lab var teach_ls_m_bl "BHQ210: male teachers, lower secondary"
lab var teach_ls_f_bl "BHQ210: female teachers, lower secondary"
lab var teach_ls_fpct_bl "BHQ210: proportion female teachers, lower secondary"
lab var teach_us_bl "BHQ210: teachers, upper secondary"
lab var teach_us_m_bl "BHQ210: male teachers, upper secondary"
lab var teach_us_f_bl "BHQ210: female teachers, upper secondary"
lab var teach_us_fpct_bl "BHQ210: proportion female teachers, upper secondary"
lab var teach_total_bl "BHQ210: total number of teachers in school"
lab var teach_p_miss_bl "BHQ210: missing value for teachers, primary"
lab var teach_ls_miss_bl "BHQ210: missing value for teachers, lower secondary"
lab var teach_us_miss_bl "BHQ210: missing value for teachers, upper secondary"

/*entrepreneurship teachers*/
qui gen teach_entr_bl=numteachers
lab var teach_entr_bl "number of entrepreneurship teachers"
forval g=1/6 {
	/*counts of entrepreneurship teachers by grade*/
	qui gen teach_entr_s`g'_bl=lev_taught_211_1S`g'+lev_taught_211_2S`g'+lev_taught_211_3S`g'+lev_taught_211_4S`g'+lev_taught_211_5S`g'
	qui gen teach_entr_s`g'_m_bl=0
	qui gen teach_entr_s`g'_f_bl=0
	qui gen teach_entr_s`g'_qual_bl=0
	qui gen teach_entr_s`g'_pt_bl=0
	qui gen teach_entr_s`g'_m_qual_bl=0
	qui gen teach_entr_s`g'_f_qual_bl=0
	lab var teach_entr_s`g'_bl "BHQ211: number of S`g' entrepreneurship teachers (max 5)"
	lab var teach_entr_s`g'_m_bl "BHQ211: number of male S`g' entrepreneurship teachers (max 5)"
	lab var teach_entr_s`g'_f_bl "BHQ211: number of female S`g' entrepreneurship teachers (max 5)"
	lab var teach_entr_s`g'_qual_bl "BHQ211: number of qualified S`g' entrepreneurship teachers (max 5)"
	lab var teach_entr_s`g'_pt_bl "BHQ211: number of part-time S`g' entrepreneurship teachers (max 5)"
	lab var teach_entr_s`g'_m_bl "BHQ211: number of qualified male S`g' entrepreneurship teachers (max 5)"
	lab var teach_entr_s`g'_f_bl "BHQ211: number of qualified female S`g' entrepreneurship teachers (max 5)"
	forval i=1/5 {
		qui replace teach_entr_s`g'_m_bl=teach_entr_s`g'_m_bl+1 if lev_taught_211_`i'S`g'==1 & gender_211_`i'==1
		qui replace teach_entr_s`g'_f_bl=teach_entr_s`g'_f_bl+1 if lev_taught_211_`i'S`g'==1 & gender_211_`i'==2
		qui replace teach_entr_s`g'_qual_bl=teach_entr_s`g'_qual_bl+1 if lev_taught_211_`i'S`g'==1 & teach_qual_211_`i'==1
		qui replace teach_entr_s`g'_pt_bl=teach_entr_s`g'_pt_bl+1 if lev_taught_211_`i'S`g'==1 & full_part_time_211_`i'==2
		qui replace teach_entr_s`g'_m_qual_bl=teach_entr_s`g'_m_qual_bl+1 if lev_taught_211_`i'S`g'==1 & gender_211_`i'==1 & teach_qual_211_`i'==1
		qui replace teach_entr_s`g'_f_qual_bl=teach_entr_s`g'_f_qual_bl+1 if lev_taught_211_`i'S`g'==1 & gender_211_`i'==2 & teach_qual_211_`i'==1
	}
	/*proportions of entrepreneurship teachers by grade*/
	qui gen teach_entr_s`g'_fpct_bl=teach_entr_s`g'_f_bl/teach_entr_s`g'_bl
	qui gen teach_entr_s`g'_qualpct_bl=teach_entr_s`g'_qual_bl/teach_entr_s`g'_bl
	qui gen teach_entr_s`g'_ptpct_bl=teach_entr_s`g'_pt_bl/teach_entr_s`g'_bl
	qui gen teach_entr_s`g'_m_qualpct_bl=teach_entr_s`g'_m_qual_bl/teach_entr_s`g'_m_bl
	qui gen teach_entr_s`g'_f_qualpct_bl=teach_entr_s`g'_f_qual_bl/teach_entr_s`g'_f_bl
	lab var teach_entr_s`g'_fpct_bl "BHQ211: proportion female S`g' entrepreneurship teachers (of up to 5 listed)"
	lab var teach_entr_s`g'_qualpct_bl "BHQ211: proportion qualified S`g' entrepreneurship teachers (of up to 5 listed)"
	lab var teach_entr_s`g'_ptpct_bl "BHQ211: proportion part-time S`g' entrepreneurship teachers (of up to 5 listed)"
	lab var teach_entr_s`g'_m_qualpct_bl "BHQ211: proportion qualified S`g' male entrepreneurship teachers (of up to 5 listed)"
	lab var teach_entr_s`g'_f_qualpct_bl "BHQ211: proportion qualified S`g' female entrepreneurship teachers (of up to 5 listed)"
}

/*counts and percentages of entrepreneurship teachers, across all grades*/
order gender_211_? teach_qual_211_? full_part_time_211_?
qui egen teach_entr_m_bl=anycount(gender_211_1-gender_211_5), v(1)
qui egen teach_entr_f_bl=anycount(gender_211_1-gender_211_5), v(2)
qui egen teach_entr_qual_bl=rowtotal(teach_qual_211_1-teach_qual_211_5)
qui egen teach_entr_pt_bl=anycount(full_part_time_211_1-full_part_time_211_5), v(2)
qui gen teach_entr_m_qual_bl=.
qui gen teach_entr_f_qual_bl=.
qui replace teach_entr_m_qual_bl=0 if teach_entr_m_bl>0
qui replace teach_entr_f_qual_bl=0 if teach_entr_f_bl>0
forval i=1/5 {
	qui replace teach_entr_m_qual_bl=teach_entr_m_qual_bl+1 if gender_211_`i'==1 & teach_qual_211_`i'==1
	qui replace teach_entr_f_qual_bl=teach_entr_f_qual_bl+1 if gender_211_`i'==2 & teach_qual_211_`i'==1
}
foreach x in f qual pt {
	qui gen teach_entr_`x'pct_bl=teach_entr_`x'_bl/teach_entr_bl
}
foreach x in m f {
	qui gen teach_entr_`x'_qualpct_bl=teach_entr_`x'_qual_bl/teach_entr_`x'_bl
}
lab var teach_entr_m_bl "BHQ211: number of male entrepreneurship teachers (max 5)"
lab var teach_entr_f_bl "BHQ211: number of female entrepreneurship teachers (max 5)"
lab var teach_entr_qual_bl "BHQ211: number of qualified entrepreneurship teachers (max 5)"
lab var teach_entr_pt_bl "BHQ211: number of part-time entrepreneurship teachers (max 5)"
lab var teach_entr_fpct_bl "BHQ211: proportion female entrepreneurship teachers"
lab var teach_entr_qualpct_bl "BHQ211: proportion qualified entrepreneurship teachers"
lab var teach_entr_ptpct_bl "BHQ211: proportion part-time entrepreneurship teachers"
lab var teach_entr_m_qualpct_bl "BHQ211: proportion qualified male entrepreneurship teachers"
lab var teach_entr_f_qualpct_bl "BHQ211: proportion qualified female entrepreneurship teachers"

/*number of additional entrepreneurship grades taught by S4 entrepreneurship teachers*/
forval i=1/5 {
	qui gen teach_entr_s4_oth`i'_bl=.
	qui replace teach_entr_s4_oth`i'_bl=0 if lev_taught_211_`i'S4==1
	foreach g in 1 2 3 5 6 {
		qui replace teach_entr_s4_oth`i'_bl=teach_entr_s4_oth`i'_bl+1 if lev_taught_211_`i'S`g'==1
	}
	lab var teach_entr_s4_oth`i'_bl "BHQ211: number of entrepreneurship grades in addition to S4 taught by teacher `i'/5"
}
order teach_entr_s4_oth?_bl
qui egen teach_entr_s4_othavg_bl=rowmean(teach_entr_s4_oth1_bl-teach_entr_s4_oth5_bl)
lab var teach_entr_s4_othavg_bl "BHQ211: avg. number of entrepreneurship grades taught in addition to S4 at school"

/*teacher absences*/
qui gen attendance_record_bl=(rec_attend_212==2)
qui egen teach_absent_avg_bl=rowmean(abs_tues1_213 abs_tues2_213 abs_tues3_213)
qui gen teach_absent_pct_bl=teach_absent_avg_bl/teach_total_bl
qui gen teach_absent_pct_miss_bl=(teach_absent_pct_bl==.)
lab var attendance_record_bl "BHQ212: showed teacher attendance records"
lab var teach_absent_avg_bl "BHQ213: teacher absences, average of last 3 Tuesdays"
lab var teach_absent_pct_bl "BHQ213/BHQ210: teacher absences, proportion of total"
lab var teach_absent_pct_miss_bl "BHQ213/BHQ210: missing value for teacher absences, proportion of total"

/*physical conditions*/
/*also BHQ215 on type of electric power source (grid, electricity, solar)*/
qui gen library_bl=(library_214==1)
qui gen electricity_now_bl=(elec_avail_216==1)
lab var library_bl "BHQ214: school has library"
lab var electricity_now_bl "BHQ216: electricity working at time of visit"


**********************************************************************
*											   				 		 *
* 		SECTION 3: School Finances and Resources	 	 	 		 *
* 														     		 *
**********************************************************************

qui gen fees_bl=(fees_parents_300==1)
qui gen fees_amt_bl=amt_fees_301 if fees_bl==1
qui replace fees_amt_bl=. if fees_amt_bl<0
foreach x in textb money {
	foreach s in govt ngo committee {
		qui gen `x'_`s'_bl=`x'_`s'_302
		qui replace `x'_`s'_bl=0 if `x'_`s'_bl<0
		lab var `x'_`s'_bl "BHQ302: `x' received from `s'"
	}
	qui gen `x'_rec_bl=`x'_govt_bl+`x'_ngo_bl+`x'_committee_bl
	qui gen `x'_rec_pc_bl=`x'_rec_bl/enroll_total_bl
	lab var `x'_rec_bl "BHQ302: `x' received from all sources"
	lab var `x'_rec_pc_bl "BHQ302: `x' received from all sources, per student"
}
qui gen fees_amt_usd_bl=fees_amt_bl/`xrate'
lab var fees_bl "BHQ300: school collects fees"
lab var fees_amt_bl "BHQ301: annual fees per student (FRW)"
lab var fees_amt_usd_bl "BHQ301: annual fees per student (USD)"

**********************************************************************
*											   				 		 *
* 					SECTION 4: School Management	 	 	 		 *
* 														     		 *
**********************************************************************
/*see also: opening/closing/break times, q400
			days closed, q401
			reason for closure, q402
			staff meeting, q404
			teaching hours legally required, q406
			number of school-level exams, q408
			methods to analyze exam results, q410
			methods to punish students, q411
			methods to reward students, q412
			factors used in hiring teachers, q415
			number of other public/private schools in sector, q416
			*/
			
qui gen lost_instruction_bl=(instr_time_lost_403==1)
qui gen teach_dev_plan_bl=(devplan_405==2)
qui gen teach_observe_bl=(cond_records_407==2)
qui gen analyze_exam_results_bl=(anal_res_409==1)
qui gen need_more_teachers_bl=(add_teach_413==1)
qui gen num_teachers_needed_bl=number_add_teach_414
qui replace num_teachers_needed_bl=0 if num_teachers_needed_bl==.
lab var lost_instruction_bl "BHQ403: instructional time lost due to school closure this term"
lab var teach_dev_plan_bl "BHQ405: has teacher professional development plan (with description)"
lab var teach_observe_bl "BHQ407: has records of classroom observations"
lab var analyze_exam_results_bl "BHQ409: conducted analysis of last exam results"
lab var need_more_teachers_bl "BHQ413: more teachers needed"
lab var num_teachers_needed_bl "BHQ414: number of additional teachers needed"


**********************************************************************
*											   				 		 *
* 			  SECTION 5: Community Participation	 	 	 		 *
* 														     		 *
**********************************************************************
/*see also: presence of parent-teacher committee, q500: 100% yes
			challenges to promote learning, q502 (useful to tabulate)*/
qui gen pta_num_mtgs_bl=times_meet_501
qui replace pta_num_mtgs_bl=. if times_meet_501==-99
lab var pta_num_mtgs_bl "BHQ501: number of parent-teacher committee meetings this term"


**********************************************************************
*											   				 		 *
* 		  SECTION 6: Pedagogy and competence-based curriculum 	 	 *
* 														     		 *
**********************************************************************
/* classify these methods as "active learning":
	--question & answer
	--small group work
	--games
	--activities outside classroom
	--experiment
	--student portfolio (not always listed)*/
/*code REMOVES discussion and practice exercises, as these did not appear in pre-analysis plan or JDE Registered Report*/

local active_mostcomf "teach_meth_mostcomf_QandA teach_meth_mostcomf_GroupWork teach_meth_mostcomf_Games teach_meth_mostcomf_ActOutClass teach_meth_mostcomf_Experiment"
local active_leastcomf "teach_meth_leastcomf_QandA teach_meth_leastcomf_GroupWork teach_meth_leastcomf_Games teach_meth_leastcomf_ActOutClass teach_meth_leastcomf_Experiment"
local active_exam_leastef "meth_5_607_QandA meth_5_607_GroupWork meth_5_607_Games meth_5_607_ActOutClass meth_5_607_Experiment meth_5_607_Portfolio"
local active_entr_mostef "meth_3_614_QandA meth_3_614_GroupWork meth_3_614_Games meth_3_614_ActOutClass meth_3_614_Experiment meth_3_614_Portfolio"
local active_entr_leastef "meth_3_615_QandA meth_3_615_GroupWork meth_3_615_Games meth_3_615_ActOutClass meth_3_615_Experiment meth_3_615_Portfolio"


foreach x in mostcomf leastcomf exam_leastef entr_mostef entr_leastef {		
	qui egen ht_pedagogy_actv_`x'_bl=rowtotal(`active_`x'')
}
lab var ht_pedagogy_actv_mostcomf_bl "BHQ600: head teacher: # active learning strategies among 3 most comfortable methods"	
lab var ht_pedagogy_actv_leastcomf_bl "BHQ601: head teacher: # active learning strategies among 3 least comfortable methods"	
lab var ht_pedagogy_actv_exam_leastef_bl "BHQ607: head teacher: # active learning strategies among 5 least effective for passing exam"
lab var ht_pedagogy_actv_entr_mostef_bl "BHQ614: head teacher: # active learning strategies among 3 most effective for entrepreneurship"
lab var ht_pedagogy_actv_entr_leastef_bl "BHQ615: head teacher: # active learning strategies among 3 least effective for entrepreneurship"

qui gen ht_pedagogy_active_bl=(ht_pedagogy_actv_entr_mostef_bl>=2 & ht_pedagogy_actv_entr_mostef_bl!=.)
qui gen ht_pedagogy_active_ineff_bl=(ht_pedagogy_actv_entr_leastef_bl<2 & ht_pedagogy_actv_entr_leastef_bl!=.)
qui gen ht_pedagogy_active_index_bl=ht_pedagogy_actv_entr_mostef_bl + (3-ht_pedagogy_actv_entr_leastef_bl)
lab var ht_pedagogy_active_bl "BHQ614: HT interactive pedagogy at least 2 of 3 most effective"
lab var ht_pedagogy_active_ineff_bl "BHQ615: HT interactive pedagogy 0 or 1 (of 3) least effective"
lab var ht_pedagogy_active_index_bl "BHQ614-615: HT interactive pedagogy support index (0=least supportive, 6=most supportive)"

* alternative classification 
/* classify these methods as "active learning":
	--small group work
	--games
	--research
	--activities outside classroom
	--practice exercises
	--experiment
	--student portfolio*/
	
local active2_mostcomf "teach_meth_mostcomf_GroupWork teach_meth_mostcomf_Games teach_meth_mostcomf_Research teach_meth_mostcomf_ActOutClass teach_meth_mostcomf_PracticeEx teach_meth_mostcomf_Experiment"
local active2_leastcomf "teach_meth_leastcomf_GroupWork teach_meth_leastcomf_Games teach_meth_leastcomf_Research teach_meth_leastcomf_ActOutClass teach_meth_leastcomf_PracticeEx teach_meth_leastcomf_Experiment"
local active2_exam_leastef "meth_5_607_GroupWork meth_5_607_Games meth_5_607_Research meth_5_607_ActOutClass meth_5_607_PracticeEx meth_5_607_Experiment meth_5_607_Portfolio"
local active2_entr_mostef "meth_3_614_GroupWork meth_3_614_Games meth_3_614_Research meth_3_614_ActOutClass meth_3_614_PracticeEx meth_3_614_Experiment meth_3_614_Portfolio"
local active2_entr_leastef "meth_3_615_GroupWork meth_3_615_Games meth_3_615_Research meth_3_615_ActOutClass meth_3_615_PracticeEx meth_3_615_Experiment meth_3_615_Portfolio"

foreach x in mostcomf leastcomf exam_leastef entr_mostef entr_leastef {		
	qui egen ht_pedgy_actv2_`x'_bl=rowtotal(`active_`x'')		
	notes ht_pedgy_actv2_`x'_bl: "active (E! definition) includes small group work, games, research, activities outside classroom, practice exercises, experiment, student portfolio"
}

lab var ht_pedgy_actv2_mostcomf_bl "BHQ600: HT: # active learning strategies among 3 most comfortable methods (E! definition)"	
lab var ht_pedgy_actv2_leastcomf_bl "BHQ601: HT: # active learning strategies among 3 least comfortable methods (E! definition)"	
lab var ht_pedgy_actv2_exam_leastef_bl "BHQ607: HT: # active learning strategies among 5 least effective for passing exam (E! definition)"
lab var ht_pedgy_actv2_entr_mostef_bl "BHQ614: HT: # active learning strategies among 3 most effective for entrepreneurship (E! definition)"
lab var ht_pedgy_actv2_entr_leastef_bl "BHQ615: HT: # active learning strategies among 3 least effective for entrepreneurship (E! definition)"

/*clubs*/
/*any clubs, q602: almost all say yes*/
qui gen businessclub_bl=(entr_club_603==1)
qui gen businessclub_sell_bl=(club_sell_604==1)
qui replace businessclub_sell_bl=. if businessclub_bl==0
qui gen businessclub_earn_bl=(club_earn_605==1)
qui replace businessclub_earn_bl=. if businessclub_sell_bl!=1
lab var businessclub_bl "BHQ603: school has business club"
lab var businessclub_sell_bl "BHQ604: business club sells products (conditional on existence of club)"
lab var businessclub_earn_bl "BHQ605: business club earns money (conditional on selling products)"

/*competency-based curriculum*/
/*other interesting variables to tabulate:
	reason teachers did not adopt competence-based approach, q613
	how to improve lesson quality, q617
	biggest challenges to high quality lessons, q618
	materials received for new curriculum, q619*/
qui gen goalteach_shld_knowledge_bl=(goal_teach_606==1)
qui gen goalteach_shld_skill_bl=(goal_teach_606==2|goal_teach_606==3)
qui gen goalteach_shld_attitude_bl=(goal_teach_606==2|goal_teach_606==3)
qui gen ht_compbased_usealways_bl=(freq_comp_608==1)
qui gen ht_compbased_rebtrain_bl=(learn_comp_609==1)
qui gen ht_skillslab_aware_bl=(skilllab_610==1)
qui gen ht_skillslab_definition_bl=(def_skilllab_611==2)
qui gen ht_skillslab_definition_cond_bl=ht_skillslab_definition_bl if ht_skillslab_aware_bl==0
qui gen compbased_refuse_bl=(not_comp_612==1)
qui gen assess_higherorder_bl=(assess_616_Answer==1)
lab var goalteach_shld_knowledge_bl "BHQ606: teachers' goal should be develop student knowledge"
lab var goalteach_shld_skill_bl "BHQ606: teachers' goal should be develop student skills"
lab var goalteach_shld_attitude_bl "BHQ606: teachers' goal should be develop student attitudes"
lab var ht_compbased_usealways_bl "BHQ608: head teacher: teachers use competency-based approach every lesson"
lab var ht_compbased_rebtrain_bl "BHQ609: head teacher: teachers learned competency-based curriculum from REB training"
lab var ht_skillslab_aware_bl "BHQ610: head teacher aware of Skills Lab"
lab var ht_skillslab_definition_bl "BHQ611: head teacher knows definition of Skills Lab"
lab var ht_skillslab_definition_cond_bl "BHQ611: head teacher knows definition of Skills Lab (conditional on awareness)"
lab var compbased_refuse_bl "BHQ612: some teachers did not adopt competence-based approach"
lab var assess_higherorder_bl "BHQ616: important to assess student use of higher-order thinking skills"

qui egen skillbasedsupport_bl=rowmean(goalteach_shld_skill_bl ht_compbased_usealways_bl ht_skillslab_aware_bl)
lab var skillbasedsupport_bl "BHQ606/608/610: index of support for skill-based learning"

/*entrepreneurship teachers & absences*/
/*enumerator verification of absences, enumver_620: almost 100%*/
qui gen num_entr_teach_bl=teach_620
qui gen absent_entr_teach_bl=teach_620-teach_pres_620
qui gen absent_entr_teach_pct_bl=absent_entr_teach_bl/num_entr_teach_bl
lab var num_entr_teach_bl "BHQ620: number of entrepreneurship teachers at school"
lab var absent_entr_teach_bl "BHQ620: number of entrepreneurship teachers absent on day of survey"
lab var absent_entr_teach_pct_bl "BHQ620: proportion of entrepreneurship teachers absent on day of survey"

* save data
qui gen insample_bl=1
lab var insample_bl "in baseline sample"

qui compress
lab data "Head teacher baseline survey (2016), modified from cleaned data"
save "$cleandata/headteacher_baseline_clean_jde.dta", replace	
	
local end=`"$S_TIME"' 
di "`start'"
di "`end'"
